<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/30
 * Time: 13:20
 */

namespace Admin\Controller;
use Think\Controller;
class SelfController extends Controller
{
    public function index()
    {
        $this->checkSession();
        $e_id = $_SESSION['employe_id'];
        $this->assign("e_id",$e_id);
        $this->display();
    }
    public function update_pass(){
        $this->checkSession();
        $e_id = $_SESSION['employe_id'];
        $employe=M('employe')->where("employe_id='$e_id'")->find();
        $this->assign("employe_password",$employe['employe_password']);
        $password=md5($_POST['old_pass']);
        if($employe['employe_password']==$password)
        {
            $data['employe_password'] = md5($_POST['new_pass1']);
            $condition['employe_id']=$e_id;
            $result=M("employe")->where($condition)->data($data)->save();
            if($result !==false) {

                $this->success('修改成功，请记住你的新密码！');
            }else{
                $this->error("异常错误，请稍后重试！");
            }
        }
        else{
            $this->error("你输入的原密码错误！");
        }
    }
    public function log(){
        $this->checkSession();
        $now = date('Y-m-d 00:00:00');
        $emplye=$_SESSION['employe_id'];



        $record = M('log');
        if ($order =$record->where("operator='$emplye'and time>='$now'")->count()) {
            $per = 15;
            import('Org.Util.Page');
            $page = new \Page($order,$per);
            $sql = "select * from hotel_log where operator='$emplye' AND time>='$now'".$page->limit;//显示订单入住时间在今天以及之后的
            $query = $record -> query($sql);
            $pageList=$page->fpage();
            $this->assign('param',$query);
            $this->assign('pageList',$pageList);
            $this->assign('num',1);
            $this->display();
        }
        else{
            $this->error("今日暂无操作记录");
        }

    }

    public function checkSession(){
        $employe_id = $_SESSION['employe_id'];
        if(isset($employe_id)){
            $this->assign('employe_id',$employe_id);
        }else{
            $this->error("需先登录,方可进行查询！",U('Login/index'));
        }
    }
}